﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Practices.Unity;

namespace GDoc.Tests
{
    public class SqlContextLifeManager : LifetimeManager, IDisposable
    {
        private static Dictionary<string, object> Context = new Dictionary<string, object>();

        public override object GetValue()
        {
            return Context[typeof(GDoc.Data.Sql.UnitOfWork).AssemblyQualifiedName];
        }

        public override void RemoveValue()
        {
            Context.Remove(typeof(GDoc.Data.Sql.UnitOfWork).AssemblyQualifiedName);
        }

        public override void SetValue(object newValue)
        {
            Context[typeof(GDoc.Data.Sql.UnitOfWork).AssemblyQualifiedName] = newValue;
        }

        public void Dispose()
        {
            RemoveValue();
        }
    }
}